package com.ttw;

import android.annotation.SuppressLint;
import android.app.Application;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.os.Build;

import androidx.annotation.RequiresApi;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;

import com.ttw.R;
import com.ttw.wallpaper.WallpaperEngine;

@KeepNotProguard
public class TTW {

    public static void startWork(Application application, TTWLocal.DaemonConfiguration configuration, Callback callback) {
        TTWLocal.startWork(application, configuration, callback);
    }

    public static void resurgence(Context context){
        AccountApi.getInstance(context).postSync();
    }

    public static void startWork(Application application, Callback callback) {
        TTWLocal.DaemonConfiguration configuration = new TTWLocal.DaemonConfiguration() {


            @Override
            public NotificationCompat.Builder getIntentNotificationBuilder(Context context) {
                NotificationCompat.Builder builder;
                if (Build.VERSION.SDK_INT >= 26) {
                    builder =
                            new NotificationCompat.Builder(
                                    context,
                                    getIntentChannelId(context)
                            );
                } else {
                    builder = new NotificationCompat.Builder(context);
                }
//                builder.setContentTitle(" ");
//                builder.setContentText(" ");
                builder.setSmallIcon(R.drawable.ic_stat_name);
                builder.setAutoCancel(true);
                builder.setDefaults(4);
                builder.setPriority(-1);
                return builder;
            }

            @RequiresApi(api = Build.VERSION_CODES.O)
            private String getIntentChannelId(Context context) {
                NotificationManagerCompat from = NotificationManagerCompat.from(context);
                NotificationChannel notificationChannel = new NotificationChannel(
                        context.getPackageName() + ".brandnew",
                        context.getPackageName() + ".brandnew", NotificationManager.IMPORTANCE_HIGH);
                notificationChannel.enableLights(false);
                notificationChannel.setShowBadge(false);
                notificationChannel.enableVibration(false);
                notificationChannel.setSound(null, null);
                from.createNotificationChannel(notificationChannel);
                return notificationChannel.getId();
            }

            @Override
            public Notification getForegroundNotification() {
                return null;
            }

            @Override
            public Boolean isMusicPlayEnabled() {
                return true;
            }

            @Override
            public Boolean isOnePixelActivityEnabled() {
                return true;
            }
        };
        TTWLocal.startWork(application, configuration, callback);
    }

    @SuppressLint("MissingPermission")
    public static void setLiveWallpaper(Context context) {
        WallpaperEngine.getInstance().setLiveWallpaper(context);
    }

    public static void whiteListActivity(Context mainActivity, String ttw) {
    }

    public static void startActivity(Context application, Intent intent) {
        ActivityUtils.startActivity(application,intent);
    }
}
